<template>
  <el-select v-model="model" filterable :placeholder="placeholder" @change="change">
    <el-option v-if="showSameUp" label="同上" value="sameUp"></el-option>
    <el-option v-for="item in options"
               :key="item.value"
               :label="item.text"
               :value="item.value">
    </el-option>
  </el-select>
</template>

<script>
import {getPosition} from '@/utils/selectOptions'
export default {
  name: 'SelectWarehouse',
  props: {
    placeholder: {
      type: String,
      default: '请选择'
    },
    value: {
      type: String,
      default: ''
    },
    id: {
      type: String,
      require: true
    },
    showSameUp: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      options: [],
      model: this.value
    }
  },
  created() {
    getPosition({orderId: this.id}).then(arr => {
      this.options = arr
    })
  },
  watch: {
    value(val, oldVal) {
      if (val === oldVal) {
        return
      }
      this.model = val
    }
  },
  methods: {
    change(val) {
      this.$emit('input', val)
      this.$emit('change', val)
    }
  }
}
</script>
